<template>
    <div class="home-recommond">
        <h3>推荐歌单</h3>
       <div class="wrapper" ref="wrapper"><!--滚动所需的容器-->
        <ul class="content" ref="content">
            <li v-for="(item,index) in listData" :key="index"
            @click="selectItem(item)">
                <div class="cover">
                    <van-image :src="item.cover"/>
                    <span>{{item.listen_num | numFilter(1)}}万</span>
    </div>
    <span>{{item.title}}</span>
    </li>
        </ul>
        </div>
       </div>
</template>
<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js";
export default{
    data(){
        return{
            listData:[],
        };
    },
created(){
    this.getSongListData()
},
    methods:{//获取到歌单的数据
        getSongListData(){
            this.$request("get","/recommend/playlist/u").then((res) => {
                // console.log(res);
                if(res.result == 100){
                    this.listData = res.data.list.slice(0,6);
                }
        betterScrollHorizontal(
            //动态获取到内容区的宽度
            this,
               this.$refs.wrapper,
               this.$refs.content,
               this.listData.length,
               10
                );
            });
    },
      selectItem(item){//列表项的点击事件
        const id = item.content_id;
         this.$router.push({path:`/singlist/${id}`})

    },
    },
    filters:{
        //处理播放量的显示格式
        /**
         * param num:小数位固定的位数
         * param value:小数的数值
         */
        numFilter(value,num){
            //把小数位固定为num位
            return parseFloat(value/10000).toFixed(num)
        },
    },
    };
</script>
<style scoped>
/* .home-recommond>ul{
    display:flex;
    flex-wrap:wrap;
}
.home-recommond>ul>li{
    width: calc((100% - 1rem) / 3 * 1);
}
.home-recommond>ul>li:nth-of-type(3n+2){
    margin-left: 0.5rem;
    margin-right:0.5rem;
}*/
.cover{
    position: relative;
}
 .cover>span{
    position: absolute;
    right: 0.2rem;
    bottom: 0.4rem;
    background-color:#a6a0a0;
    color: white;
    font-size: 14px;
    border-radius: 1rem;
    width: 5rem;
    display: inline-block;
} 
.wrapper{
    /*容器的宽度就是屏幕的额宽度*/
    width: 100%;
    overflow: hidden;
}
/* ul.content{
    /* content内容区的宽度要大于wrapper容器的宽度，12个列表项 */
    /*width: calc(12 * 10rem);
/*} */
ul.content li{
    width: 10rem;
    /** li默认是块级元素，修改为行内元素，但是要具备块级元素的特性*/
    display: inline-block;
    vertical-align: top;
}
ul.content li *{
    margin: 0.1rem;
}

</style>